﻿using System;
using System.Windows.Forms; 
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QuickTuner
{
    /// <summary>
    /// The play engine implementation for winforms QuickTuner client.
    /// Use the Internet Explorer control to renders the webpage
    /// </summary>
    public class IEPlayEngine : IPlayEngine
    {
        private bool _isPlaying;
        private string _currentUrl;
        private WebBrowser _browser;

        public IEPlayEngine()
        {
            _isPlaying = false;
            _currentUrl = string.Empty;
            _browser = new WebBrowser();
        }

        #region IPlayEngine Members

        public bool IsPlaying
        {
            get { return _isPlaying; }
        }

        public string CurrentUrl
        {
            get { return _currentUrl; }
        }

        public bool MustStopBeforePlay
        {
            // no need to stop before play, just change url in IE
            get { return false; }
        }

        public void Play(string stationUrl)
        {
            _browser.Stop();

            _currentUrl = stationUrl;
            _isPlaying = true;
            _browser.Navigate(stationUrl);
        }

        public void Stop()
        {
            _currentUrl = string.Empty;
            _isPlaying = false;
            _browser.Stop();
        }

        #endregion

    }
}
